Skip to content

Conversation

@anth-volk
Copy link
Collaborator

Fixes #584

Summary

This PR migrates the frontend to fetch metadata from the new PolicyEngine API v2 alpha endpoints. Key changes include:

  • V2 API Integration: New modules for fetching parameters, variables, datasets, and parameter values from V2 endpoints using tax_benefit_model_name (e.g., "policyengine-us") instead of UUIDs
  • Static Metadata Hooks: New useStaticMetadata hooks replace Redux selectors for accessing static data (regions, entities, currentLawId)
  • IndexedDB Caching: Updated to work with the new V2 data format
  • Component Migrations: Updated all components that were accessing removed MetadataState properties

Changes

New V2 API Modules (app/src/api/v2/)

File Purpose
taxBenefitModels.ts Country-to-model-name mapping and utilities
parameters.ts Fetch parameters with tax_benefit_model_name filter
variables.ts Fetch variables with tax_benefit_model_name filter
datasets.ts Fetch datasets with tax_benefit_model_name filter
parameterValues.ts Fetch parameter values by parameter ID

Static Metadata Migration

New useStaticMetadata.ts hooks provide:

  • useRegionsList(countryId, year) - Get available regions
  • useCurrentLawId(countryId) - Get current law policy ID
  • useEntitiesList(countryId) - Get entity definitions

Production Files Updated

File Change
useFetchReportIngredients.ts Use useRegionsList() instead of state.metadata.economyOptions.region
useSaveSharedReport.ts Use useCurrentLawId() instead of state.metadata.currentLawId
AbsoluteChangeByDistrict.tsx Use useRegionsList() for congressional district regions
RelativeChangeByDistrict.tsx Use useRegionsList() for congressional district regions

UI Improvements

  • Added loading states (Skeleton, LoadingOverlay) to parameter setter while values load

Type Fixes

  • Installed @types/topojson-client and @types/topojson-specification for choropleth map types

Tests

All tests updated to mock static metadata hooks instead of Redux:

  • useSaveSharedReport.test.tsx
  • AbsoluteChangeByDistrict.test.tsx
  • RelativeChangeByDistrict.test.tsx
  • New V2 API module tests

All mocks moved to tests/fixtures/ following project conventions.

Test plan

  • Run npm run typecheck - passes
  • Run npm test - all tests pass
  • Verify metadata loads correctly in development
  • Verify parameter values load with loading spinner
  • Verify congressional district maps display correctly

🤖 Generated with Claude Code

@vercel
Copy link

vercel bot commented Jan 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
policyengine-app-v2 Ready Ready Preview, Comment Jan 20, 2026 1:28pm
policyengine-calculator Ready Ready Preview, Comment Jan 20, 2026 1:28pm
policyengine-website Ready Ready Preview, Comment Jan 20, 2026 1:28pm

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate metadata fetching to API v2 alpha

2 participants